package com.xuyu.nacos.callback.testmodel;

import com.alibaba.nacos.api.config.ConfigChangeItem;
import com.xuyu.nacos.callback.listener.annoation.NacosListener;
import com.xuyu.nacos.callback.listener.annoation.NacosListenerCallBackMethod;
import com.xuyu.nacos.callback.listener.annoation.OnChangeCallBack;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;

/**
 * @author xuyu
 *
 * 这个类展示了使用的方法
 */
@Component
@RefreshScope
@NacosListener
public class MyNacosConfig {


    /**
     * 开关配置
     */
    @Value(value = "${function.switch.controller:false}")
    @OnChangeCallBack(methodClass = MyNacosConfig.class, method = "changeSwitchField")
    private boolean controller;


    @NacosListenerCallBackMethod(key = "function.switch.controller")
    public void changeSwitch(ConfigChangeItem configChangeItem) {
        System.out.println("我是使用了方法注册的监听哦" + configChangeItem.getNewValue());
    }


    public void changeSwitchField(ConfigChangeItem configChangeItem) {
        System.out.println("我是使用字段监听方式哦" + configChangeItem.getNewValue());
    }


}
